package com.taimi.springbootzendaodemo.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import lombok.Data;

@Component
@Data
public class EnvironmentUtils {

    public static final String TEST = "test";

    @Autowired
    private Environment env;

    public String[] getActiveProfiles() {
        return env.getActiveProfiles();
    }

    public boolean isTest() {
        for (String profile : getActiveProfiles()) {
            if (TEST.equals(profile)) {
                return true;
            }
        }
        return false;
    }

    public boolean isNotTest() {
        for (String profile : getActiveProfiles()) {
            if (TEST.equals(profile)) {
                return false;
            }
        }
        return true;
    }
}
